package com.spq.paramsverify.controller;

import com.mysql.cj.util.StringUtils;
import com.spq.paramsverify.entity.Student;
import com.spq.paramsverify.maker.Add;
import com.spq.paramsverify.maker.Update;
import com.spq.paramsverify.req.AddOrEditStudentReq;
import com.spq.paramsverify.resp.StudentResp;
import com.spq.paramsverify.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author gongjianpeng
 * @Date 2022/1/19
 */
@RestController
public class StudentController {

    @Resource
    StudentService studentService;

    @PostMapping("/addStudent")
    public boolean addStudent(@Validated({Add.class}) @RequestBody AddOrEditStudentReq req) {
        return studentService.addStudent(req);
    }

    @PostMapping("/getStudent")
    public StudentResp getStudent(Long id) {
        StudentResp student = studentService.getStudent(id);
        return student;
    }

    @PostMapping("/updateStudent")
    public String updateStudent(@Validated(Update.class) @RequestBody AddOrEditStudentReq req) {
        if (studentService.updateStudent(req)) {
            return "添加成功";
        } else {
            return  "添加失败";
        }
    }
}
